package com.wing.cabinet.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.cabinet.dao.StoresRequisitionProductDao;
import com.wing.cabinet.model.entity.StoresRequisitionProduct;
import com.wing.cabinet.model.request.StoresRequisitionProductForm;
import com.wing.cabinet.model.response.StoresRequisitionProductVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 领新申请产品表-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class StoresRequisitionProductServiceImpl extends ServiceImpl<StoresRequisitionProductDao, StoresRequisitionProduct> implements StoresRequisitionProductService {

    @Override
    public int add(StoresRequisitionProductForm storesRequisitionProductForm) {

        //校验

        StoresRequisitionProduct storesRequisitionProduct =new StoresRequisitionProduct();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(StoresRequisitionProduct.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(storesRequisitionProductForm, storesRequisitionProduct, copyOptions);

        return baseMapper.insert(storesRequisitionProduct);
    }

    @Override
    public List<StoresRequisitionProductVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<StoresRequisitionProductVO> pageList4app(Page page, Map<String, Object> params) {
        List<StoresRequisitionProductVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public StoresRequisitionProductVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

    @Override
    public IPage<StoresRequisitionProductVO> getStoresRequisitionProductVOPageList(Long storesRequisitionId, Integer page, Integer limit) {
        IPage<StoresRequisitionProductVO> iPage = new Page<>();
        QueryWrapper<StoresRequisitionProduct> wrapper = new QueryWrapper<>();
        if(storesRequisitionId != null){
            wrapper.eq("stores_requisition_id",storesRequisitionId);
        }
        baseMapper.getStoresRequisitionProductVOPageList(iPage,wrapper);
        return iPage;
    }

    @Override
    public List<StoresRequisitionProductVO> getStoresRequisitionProductVOInfo(Long storesRequisitionId) {
        return baseMapper.getStoresRequisitionProductVOInfo(storesRequisitionId);
    }
}
